<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 如果传的自定义属性在子组件里面的props没有接受，那么他会挂载到子组件的根元素上面 -->
      <h3>props的验证</h3>
      <child
        name="juner"
        :age="40"
        :weight="200"
        :money="80000"
        :height="170"
        a="3"
      ></child>
    </div>

    <script src="../Vue.js"></script>
    <script>
      const Child = {
        props: {
          name: String,
          // 多种情况 或
          age: [String, Number],
          // 必填属性
          weight: {
            type: Number,
            required: true,
          },
          // props的默认值
          money: {
            type: Number,
            default: 50000,
          },
          height: {
            // validator叫做自定义验证函数,里面需要return true或者false
            validator(value) {
              return value > 175;
            },
          },
        },
        template: `
          <div>child组件 {{ name }} - {{ age }} - {{ money }} - {{ height }}</div>
        `,
      };
      new Vue({
        el: "#app",
        data: {},
        components: {
          Child,
        },
      });
    </script>
  </body>
</html>
